package com.campus.counseling.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.counseling.entity.ResultInterpretation;
import com.campus.counseling.model.mapper.ResultInterpretationMapper;
import com.campus.counseling.service.ResultInterpretationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ResultInterpretationServiceImpl extends ServiceImpl<ResultInterpretationMapper, ResultInterpretation> implements ResultInterpretationService {

    @Override
    public ResultInterpretation getInterpretationByScoreRange(Long testId, String dimension, Double score) {
        if (testId == null || dimension == null || score == null) {
            return null;
        }

        LambdaQueryWrapper<ResultInterpretation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResultInterpretation::getTestId, testId)
                   .eq(ResultInterpretation::getDimension, dimension)
                   .eq(ResultInterpretation::getStatus, 1)
                   .le(ResultInterpretation::getMinScore, score)
                   .ge(ResultInterpretation::getMaxScore, score);

        return getOne(queryWrapper);
    }
} 